(in-package 'user)

(defun test-sentence (item)
  (let* ((s (first item))
	 (expected (second item))
	 current)
    (format t "~%~%F-STRUCTURE: ~a" s)
    (setq current (generator s))
    (print current)
    (cond ((equal current expected)
	    (format t "~%Test Passed!")
	   t)
	  (t
	    (format t "~%Test failed: ~s" s)
	    (format t "~%Expected: ~s" expected)
	    nil))))

(defun run-tests ()
  (let ((failures 0))
    (dolist (item *tests*)
	    (unless (test-sentence item)
		    (incf failures)))
    (format t "~%~a failures." failures)))

(defun generate-tests (list)
  (let (current)
  (princ "(SETQ *TESTS* '(")
  (dolist (x list)
	  (setq current (generator x))
	  (if current
	      (pprint (list x current))
	    (format t "~%~s" (list x current))))
  (princ "))")
  nil
))

(defvar *sentences*)

(setq *she*    '((cat PRO)(person 3)(number sg)))
(setq *they*   '((cat PRO)(person 3)(number pl)))
(setq *you-sg* '((cat PRO)(person 2)(number sg)))
(setq *you-pl* '((cat PRO)(person 2)(number pl)))
(setq *i*      '((cat PRO)(person 1)(number sg)))
(setq *we*     '((cat PRO)(person 1)(number pl)))
(setq *sleep*  '((cat v)(root "sleep")(valency intrans)))
(setq *eat*    '((cat v)(root "eat")(valency (*or* trans intrans))))
(setq *the*    '(det ((cat det)(root "the"))))
(setq *figs*   `(,*the* (cat n)(person 3)(number pl)(root "fig")))
(setq *relish* `((cat n)(person 3)(number sg)(root "relish")))
(setq *with-relish* `((cat p)(root "with")(obj ,*relish*)))

(setq *sentences* 
      `(
	,*she* ,*they* ,*you-sg* ,*you-pl* ,*i* ,*we*

       (,@*sleep* (subj ,*she*))	       
       (,@*sleep* (subj ,*i*))	       
       (,@*sleep* (subj ,*they*))	       
       (,@*eat* (subj ,*she*) (obj ,*figs*))
       (,@*eat* (subj ,*she*))
       (,@*eat* (subj ,*she*)(ppadjunct ,*with-relish*))
       (,@*sleep* (subj ,*she*)(ppadjunct ,*with-relish*))
       (,@*eat* (subj ,*she*) (obj ,*figs*)(ppadjunct ,*with-relish*))
       (,@*eat* (subj ,*you-sg*) (obj ,*figs*)(ppadjunct ,*with-relish*))
       (,@*eat* (subj ,*you-sg*) (obj ,*figs*)(ppadjunct ((topic +) ,@*with-relish*)))
))

(defvar *tests*)

(SETQ *TESTS* '(
(((CAT PRO) (PERSON 3) (NUMBER SG)) "s/he")
(((CAT PRO) (PERSON 3) (NUMBER PL)) "they")
(((CAT PRO) (PERSON 2) (NUMBER SG)) "you")
(((CAT PRO) (PERSON 2) (NUMBER PL)) "you")
(((CAT PRO) (PERSON 1) (NUMBER SG)) "I")
(((CAT PRO) (PERSON 1) (NUMBER PL)) "we")
(((CAT V) (ROOT "sleep") (VALENCY INTRANS)
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER SG))))
 "s/he sleeps")
(((CAT V) (ROOT "sleep") (VALENCY INTRANS)
  (SUBJ ((CAT PRO) (PERSON 1) (NUMBER SG))))
 "I sleep")
(((CAT V) (ROOT "sleep") (VALENCY INTRANS)
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER PL))))
 "they sleep")
(((CAT V) (ROOT "eat") (VALENCY (*OR* TRANS INTRANS))
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER SG)))
  (OBJ ((DET ((CAT DET) (ROOT "the"))) (CAT N) (PERSON 3) (NUMBER PL)
        (ROOT "fig"))))
 "s/he eats the figs")
(((CAT V) (ROOT "eat") (VALENCY (*OR* TRANS INTRANS))
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER SG))))
 "s/he eats")
(((CAT V) (ROOT "eat") (VALENCY (*OR* TRANS INTRANS))
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER SG)))
  (PPADJUNCT
      ((CAT P) (ROOT "with")
       (OBJ ((CAT N) (PERSON 3) (NUMBER SG) (ROOT "relish"))))))
 "s/he eats with relish")
(((CAT V) (ROOT "sleep") (VALENCY INTRANS)
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER SG)))
  (PPADJUNCT
      ((CAT P) (ROOT "with")
       (OBJ ((CAT N) (PERSON 3) (NUMBER SG) (ROOT "relish"))))))
 "s/he sleeps with relish")
(((CAT V) (ROOT "eat") (VALENCY (*OR* TRANS INTRANS))
  (SUBJ ((CAT PRO) (PERSON 3) (NUMBER SG)))
  (OBJ ((DET ((CAT DET) (ROOT "the"))) (CAT N) (PERSON 3) (NUMBER PL)
        (ROOT "fig")))
  (PPADJUNCT
      ((CAT P) (ROOT "with")
       (OBJ ((CAT N) (PERSON 3) (NUMBER SG) (ROOT "relish"))))))
 "s/he eats the figs with relish")
(((CAT V) (ROOT "eat") (VALENCY (*OR* TRANS INTRANS))
  (SUBJ ((CAT PRO) (PERSON 2) (NUMBER SG)))
  (OBJ ((DET ((CAT DET) (ROOT "the"))) (CAT N) (PERSON 3) (NUMBER PL)
        (ROOT "fig")))
  (PPADJUNCT
      ((CAT P) (ROOT "with")
       (OBJ ((CAT N) (PERSON 3) (NUMBER SG) (ROOT "relish"))))))
 "you eat the figs with relish")
(((CAT V) (ROOT "eat") (VALENCY (*OR* TRANS INTRANS))
  (SUBJ ((CAT PRO) (PERSON 2) (NUMBER SG)))
  (OBJ ((DET ((CAT DET) (ROOT "the"))) (CAT N) (PERSON 3) (NUMBER PL)
        (ROOT "fig")))
  (PPADJUNCT
      ((TOPIC +) (CAT P) (ROOT "with")
       (OBJ ((CAT N) (PERSON 3) (NUMBER SG) (ROOT "relish"))))))
 "with relish you eat the figs")))